package com.guigu.www.erp.yinjiaxiong.service.impl;

import com.guigu.www.erp.common.dao.SGatherDetailsMapper;
import com.guigu.www.erp.common.dao.SGatherMapper;
import com.guigu.www.erp.common.pojo.SGatherDetails;
import com.guigu.www.erp.common.pojo.SPay;
import com.guigu.www.erp.common.pojo.SPayDetails;
import com.guigu.www.erp.yinjiaxiong.service.YJXsGatherDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class YJXsGatherDetailsImpl implements YJXsGatherDetailsService {
    @Autowired
    SGatherDetailsMapper sGatherDetailsMapper;

    @Autowired
    SGatherMapper sGatherMapper;

    @Override
    public int insertsGatherDetails(SGatherDetails sGatherDetails) {
        //System.out.println("入库明细表加值===="+sGatherDetails);
        //获取父序号 即上一个自增id
       // int n = sGatherMapper.getMaxsGatherprimaryKey();
        //由于异步 不能获到准确的父id 所以要加一
      //  sGatherDetails.setParentId(n+1);//设置父编号
        sGatherDetails.setAmount(Integer.parseInt(sGatherDetails.getPersonalValuue()));//设置数量
        sGatherDetails.setAmountUnit(sGatherDetails.getPersonalUnit());//设置单位
        sGatherDetails.setCostPrice(sGatherDetails.getRealCostPrice());
        sGatherDetails.setSubtotal((sGatherDetails.getAmount()*sGatherDetails.getRealCostPrice()));//设置小计
        sGatherDetails.setGatherTag("1");//设置入库标记  1为已登记
        return sGatherDetailsMapper.insertSelective(sGatherDetails);
    }

    @Override
    public List<SGatherDetails> ByparentIDquery(Integer id) {
        return sGatherDetailsMapper.ByparentIDquery(id);
    }

    @Override
    public int ByprimaryKeyupdategatherTag(Integer id) {
        return sGatherDetailsMapper.ByprimaryKeyupdategatherTag(id);
    }

    @Override
    public List<SGatherDetails> BysGatherIdquerysGatherDetailsgatherTag2(Integer id) {
        return sGatherDetailsMapper.BysGatherIdquerysGatherDetailsgatherTag2(id);
    }

    @Override
    public int ByGatherDetailsIdupdatesgatheredAmount(Integer id, Integer amount) {
        return sGatherDetailsMapper.ByGatherDetailsIdupdatesgatheredAmount(id,amount);
    }

    @Override
    public List<SPayDetails> ByspayIdquerysGatherDetailsgatherTag2(Integer id) {
        return sGatherDetailsMapper.ByspayIdquerysGatherDetailsgatherTag2(id);
    }

    @Override
    public List<SGatherDetails> ByparentIDquery2(Integer id) {
        return sGatherDetailsMapper.ByparentIDquery2(id);
    }
}
